Skip to content

[CLI]: add RPC Adapter with Inspect Diamond command - #375

Merged
maxnorm merged 6 commits into
Perfect-Abstractions:mainfrom
maxnorm:feat/rpc-adapter
Aug 15, 2026
Merged

[CLI]: add RPC Adapter with Inspect Diamond command#375
maxnorm merged 6 commits into
Perfect-Abstractions:mainfrom
maxnorm:feat/rpc-adapter

Conversation

@maxnorm

@maxnorm maxnorm commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add an RPC adapter layer to the CLI and two new commands: rpc for connection testing and inspect for querying Diamond proxy state (facets, selectors, function signatures). The RPC URL is resolved from compose.json chain definitions with environment variable interpolation support.
image
image

Changes Made

RPC Adapter (cli/src/adapters/rpc/)

  • IRPCAdapter interface: readContract and getCode methods backed by viem
  • createRPCAdapter factory: builds a viem public client with configurable retry policy (2 retries, 50ms/200ms backoff), transient-error classification, and Retry-After header support
  • Validation: rejects invalid URLs, non-HTTP(S) protocols, non-positive chain IDs
  • Error hierarchy: RPCError with stable codes (RPC_INVALID_CONFIGURATION, RPC_REQUEST_FAILED, RPC_UNAUTHORIZED, etc.)

rpc Command

  • Tests RPC connectivity for a given chain (defaults to local)
  • Optionally verifies a contract address has deployed bytecode
  • Resolves chain config from compose.json via the dependency resolver

inspect Command

  • Queries a deployed Diamond address for all facets, selectors, and function signatures via DiamondLoupe
  • Decodes selectors against common ERC/Diamond signatures and project ABI files
  • Supports both Foundry and Hardhat artifact directories (auto-detected or overridden)
  • Outputs facet tree with decoded function signatures

Infrastructure

  • chainConfig.ts: resolves chain RPC URLs from compose.json with ${ENV_VAR} interpolation
  • loadEnvFiles(): hierarchical .env loading from cwd up to filesystem root
  • Dependency resolver: new DependencyKey.RPC with factory that creates adapters on demand
  • Pipelines: thin rpcPipeline and inspectPipeline orchestrations

Tests

  • RPC adapter: chain ID verification, retry on transient failures (503), Retry-After header, non-retryable errors (401), bytecode verification
  • Inspect module: ABI loading (Foundry/Hardhat), selector decoding, invalid address handling, missing contract code
  • Commander: command registration, positional args, flag defaults
  • Chain config: env var interpolation, missing vars, invalid keys

Checklist

Before submitting this PR, please ensure:

  • Code follows the Solidity feature ban - No inheritance, constructors, modifiers, public/private variables, external library functions, using for directives, or selfdestruct

  • Code follows Design Principles - Readable, uses diamond storage, favors composition over inheritance

  • Code matches the codebase style - Consistent formatting, documentation, and patterns (e.g. ERC20Facet.sol)

  • Code is formatted with forge fmt

  • Existing tests pass - Run tests to be sure existing tests pass.

  • New tests are optional - If you don't provide tests for new functionality or changes then please create a new issue so this can be assigned to someone.

  • All tests pass - Run forge test and ensure everything works

  • Documentation updated - If applicable, update relevant documentation

  • Changesets — If this PR changes publishable packages (src/, cli/), changeset-bot will comment if a release note might be needed. You can add one when convenient or defer to maintainers.

Make sure to follow the contributing guidelines.

Additional Notes

@netlify

netlify Bot commented Aug 15, 2026

Copy link
Copy Markdown

👷 Deploy request for compose-diamonds pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 787dab2

@changeset-bot

changeset-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 787dab2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@perfect-abstractions/compose-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Coverage

Metric Coverage Details
Lines 85% 2063/2419 lines
Functions 90% 560/621 functions
Branches 89% 207/233 branches

Last updated: Sat, 15 Aug 2026 20:28:02 GMT for commit 787dab2

@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Gas Report

No gas usage changes detected between main and feat/rpc-adapter.

All functions maintain the same gas costs. ✅

Last updated: Sat, 15 Aug 2026 20:28:52 GMT for commit 787dab2

@maxnorm
maxnorm merged commit 59d9ef9 into Perfect-Abstractions:main Aug 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant